<?php
/**
 * Soar Framework - Lightweight and simple to use PHP Framework
 *
 * Soar is free software and is distributed WITHOUT ANY WARRANTY
 *
 * @package Soar
 * @version 1.0 $Id: SoarView.php 2 2012-04-06 21:50:33Z shay@shayanderson.com $
 * @copyright Copyright (c) 2012 ShayAnderson.com
 * @license http://www.gnu.org/licenses/gpl.html GPL License
 * @link http://www.shayanderson.com/projects/soar-php-framework.htm
 */

/**
 * Soar Framework Abstract Core View
 *
 * @package Soar
 * @name SoarView
 * @author Shay Anderson 04.12
 */
abstract class SoarView
{
	/**
	 * Template file has been displayed flag
	 *
	 * @var bool
	 */
	protected $_is_displayed = false;

	/**
	 * Template engine
	 *
	 * @var object
	 */
	protected $_tpl_engine;

	/**
	 * Init
	 *
	 * @param object $template_engine
	 */
	final public function __construct(&$template_engine)
	{
		Soar::log(__CLASS__ . ': initialized', SoarDebugger::LEVEL_DEBUG);
		Soar::log(get_class($template_engine) . ': initialized', SoarDebugger::LEVEL_DEBUG);
		$this->_tpl_engine = &$template_engine;
	}

	/**
	 * Template var getter
	 *
	 * @param string $var
	 * @return mixed
	 */
	final public function __get($var)
	{
		return $this->get($var);
	}

	/**
	 * Check if template var is set
	 *
	 * @param string $var
	 * @return bool
	 */
	final public function __isset($var)
	{
		return $this->get($var) !== NULL;
	}

	/**
	 * Template var setter
	 *
	 * @param string $var
	 * @param mixed $value
	 * @return void
	 */
	final public function __set($var, $value = NULL)
	{
		$this->set($var, $value);
	}

	/**
	 * Set template var null
	 *
	 * @param string $var
	 * @return void
	 */
	final public function __unset($var)
	{
		$this->set($var, NULL);
	}

	/**
	 * Echo/display template
	 *
	 * @param string $template_file_path
	 * @return void
	 */
	abstract public function display($template_file_path);

	/**
	 * Compiled template getter
	 *
	 * @param string $template_file_path
	 * @return string
	 */
	abstract public function fetch($template_file_path);

	/**
	 * Template var getter
	 *
	 * @param string $var
	 * @return mixed
	 */
	abstract public function get($var);

	/**
	 * Has template file beed displayed flag getter
	 *
	 * @return bool
	 */
	final public function isDisplayed()
	{
		return $this->_is_displayed;
	}

	/**
	 * Template var setter
	 *
	 * @param string $var
	 * @param mixed $value
	 * @return void
	 */
	abstract public function set($var, $value = NULL);
}
?>